var getFile = function(s) {
  return 'WEB-INF/template/ftl/demo/' + s + '/index.ftl';
};
var common = require('../common');

module.exports = {
  // mock 请求
  "get /getOrder": function(req, res) {
    res.send({
      result: 'success',
      messages: [],
      fieldErrors: {},
      errors: [],
      data: {
        totalCount: 22,
        pageSize: 3,
        pageIndex: 0,
        listData: [{
          "OrderLineID": 1,
          "Name": "Pineapple",
          "Price": 1.50,
          "datetime": 1398220182737,
          "Quantity": 4
        }, {
          "OrderLineID": 2,
          "Name": "Fresh Spring Onions",
          "Price": 1.10,
          "datetime": 1398220182737,
          "Quantity": 40
        }, {
          "OrderLineID": 3,
          "Name": "Oranges",
          "Price": 0.20,
          "datetime": 1398220182737,
          "Quantity": 8
        }, {
          "OrderLineID": 4,
          "Name": "Apples",
          "Price": 1.50,
          "datetime": 1398220182737,
          "Quantity": 5
        }, {
          "OrderLineID": 5,
          "Name": "Raspberries",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 20
        }, {
          "OrderLineID": 6,
          "Name": "Blueberries",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 20
        }, {
          "OrderLineID": 7,
          "datetime": 1398220182737,
          "Name": "Pairs",
          "Price": 1.50,
          "Quantity": 8
        }, {
          "OrderLineID": 8,
          "datetime": 1398220182737,
          "Name": "Melons",
          "Price": 1.50,
          "Quantity": 2
        }, {
          "OrderLineID": 9,
          "Name": "Potatoes",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 6
        }, {
          "OrderLineID": 10,
          "Name": "Sweet Potatoes",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 3
        }, {
          "OrderLineID": 11,
          "Name": "Cabbages",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 1
        }, {
          "OrderLineID": 12,
          "Name": "Lettuce",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 1
        }, {
          "OrderLineID": 13,
          "Name": "Onions",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 25
        }, {
          "OrderLineID": 14,
          "Name": "Carrots",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 30
        }, {
          "OrderLineID": 15,
          "Name": "Broccoli",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 1
        }, {
          "OrderLineID": 16,
          "Name": "Cauliflower",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 1
        }, {
          "OrderLineID": 17,
          "datetime": 1398220182737,
          "Name": "Peas",
          "Price": 1.50,
          "Quantity": 1
        }, {
          "OrderLineID": 18,
          "Name": "Sweetcorn",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 2
        }, {
          "OrderLineID": 19,
          "Name": "Gooseberries",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 20
        }, {
          "OrderLineID": 20,
          "Name": "Spring Onions",
          "datetime": 1398220182737,
          "Price": 1.50,
          "Quantity": 9
        }, {
          "OrderLineID": 21,
          "Name": "Beetroot",
          "datetime": 1398220182737,
          "Price": 0.30,
          "Quantity": 3
        }, {
          "OrderLineID": 22,
          "datetime": 1398220182737,
          "Name": "Avocado",
          "Price": 2.30,
          "Quantity": 1
        }]
      }
    });
  },
  
  "get /gallery": function(req, res) {
    var listData = [];
    var imgs = [
      'http://img04.taobaocdn.com/tfscom/tuitui/T1P6F0FSXcXXXXXXXX_100x100xz',
      'http://img04.taobaocdn.com/tfscom/tuitui/T1UO04FR0bXXXXXXXX_100x100xz',
      'http://img01.taobao.com/tfscom/i2/T1Q4BKFTXbXXXXXXXX_!!0-item_pic.jpg_100x100xz',
      'http://img04.taobaocdn.com/tfscom/tuitui/T1c001FIXdXXXXXXXX_100x100xz'
    ];
    var description = [
      '123456',
      '123456789',
      '123456454',
      '11456465'
    ];
    var pageIndex = req.body.pageIndex;
    var pageSize = req.body.pageSize;
    var totalCount = 200;
    for(var i = 0;i < totalCount;i++) {
      var index = Math.floor(Math.random() * 4);
      listData.push({
        id: i,
        title: '模板' + i,
        url: imgs[index],
        description:description[index]
      });
    }
    var pageData = common.getPageData(listData, pageIndex, pageSize);
    
    res.send({
      result: 'success',
      messages: [],
      fieldErrors: {},
      errors: [],
      data: {
        totalCount: totalCount,
        pageSize: pageData.pageSize,
        pageIndex: pageData.pageIndex,
        listData: pageData.listData
      }
    });
  }

};